package com.rowenci.iot_agriculture.mapper;

import com.rowenci.iot_agriculture.bean.admin.Admin;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface AdminDao extends JpaRepository<Admin, Integer> {

    Admin findAdminByAccountAndPassword(String account, String password);

    @Transactional
    @Modifying
    @Query(value = "update Admin admin set admin.password = ?3 where admin.account = ?1 and admin.securityno = ?2 ")
    void updatePasswordByAccount(String account, String securityno, String password);

    @Transactional
    @Modifying
    @Query(value = "update Admin admin set admin.securityno = ?3 where admin.account = ?1 and admin.securityno = ?2 ")
    void updateSecurityno(String account, String securityno_old, String securityno_new);

    Admin findAdminByAccount(String account);

}
